home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / plasma / blank.c next >
C/C++ Source or Header  |  1993-08-15  |  3KB  |  107 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <intuition/intuition.h>
  5. #include <dos/dos.h>
  6.  
  7. #include <clib/exec_protos.h>
  8. #include <clib/intuition_protos.h>
  9. #include <clib/graphics_protos.h>
  10. #include <clib/alib_protos.h>
  11.  
  12. extern    ULONG    Depth, Mode;
  13. UWORD    Colors5[] = {    0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0, 0x00F2,
  14.     0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B, 0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C,    0x060B, 0x0809,
  15.     0x0908, 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00 }, Colors4[] = {    0x0E03, 0x0B06, 0x0909, 0x060B, 0x030E,
  16.     0x003E, 0x006B, 0x0099, 0x00B6, 0x00E3, 0x03E0,    0x06B0, 0x0990, 0x0B60, 0x0E30 }, Colors3[] = {    0x0E00,
  17.     0x0770, 0x00E0, 0x0077, 0x000E, 0x0707 }, Colors2[] = {    0x0E00, 0x00E0, 0x000E }, Colors1[] = { 0x0FFF },
  18.     *Table[5], Range[] = { 32, 32, 32, 22, 14, 8, 4, 2 }, *Cell, Hei, Wid;
  19.  
  20. VOID CycleColors( struct Screen *Scr, ULONG Depth )
  21. {
  22. static    ULONG    pos = 0;
  23.     ULONG    i, j = 0, Colors = ( 1L << Depth ) - 1;
  24.  
  25.     SetRGB4(&( Scr->ViewPort ), 0, 0, 0, 0 );
  26.     for( i = pos; j < Colors; i = ++i % Colors )
  27.         SetRGB4(&( Scr->ViewPort ), ++j, ( Table[Depth-1][i] & 0x0F00 ) >> 8,
  28.             ( Table[Depth-1][i] & 0x00F0 ) >> 4, Table[Depth-1][i] & 0x000F);
  29.  
  30.     pos = ++pos % Colors;
  31. }
  32.  
  33. #define SetCell( l, c, val ) *( Cell + ( l * Wid + c )) = val;
  34. #define ValCell( l, c ) ( *( Cell + ( l * Wid + c )))
  35.  
  36. void set( UWORD l, UWORD c, UWORD size, LONG value, struct RastPort *Rast )
  37. {
  38.     UWORD rang;
  39.  
  40.     rang = Range[size];
  41.     value = value + RangeRand( rang ) - ( rang + 1 ) / 2;
  42.     if( value < 1 ) value = 1;
  43.     SetCell( l, c, value );
  44.     SetAPen( Rast, value );
  45.     WritePixel( Rast, c, l );
  46. }
  47.  
  48. void grow( struct RastPort *Rast )
  49. {
  50.     UWORD l, c, i, step, nextStep, l1, l2, c1, c2;
  51.  
  52.     SetCell( 0, 0, 0 );
  53.     step = 256;
  54.     for( i = 0; i < 8; i++ ) {
  55.         nextStep = step / 2;
  56.         for( l = 0; ( l < Hei )&&( !( SetSignal( 0, 0 ) & SIGBREAKF_CTRL_C )); l += step ) {
  57.             l1 = ( l + nextStep ) % Hei;
  58.             l2 = ( l + step ) % Hei;
  59.             for( c = 0; c < Wid; c += step ) {
  60.                 c1 = ( c + nextStep ) % Wid;
  61.                 c2 = ( c + step ) % Wid;
  62.                 set( l, c1, i, ( ValCell( l, c ) + ValCell( l, c2 ) + 1 ) / 2, Rast );
  63.                 set( l1, c, i, ( ValCell( l, c ) + ValCell( l2, c ) + 1 ) / 2, Rast );
  64.                 set( l1, c1, i, ( ValCell( l, c ) + ValCell( l, c2 ) + ValCell( l2, c ) + 
  65.                     ValCell( l2, c2 ) + 2 ) / 4, Rast );
  66.             }
  67.         }
  68.         step = nextStep;
  69.     }
  70. }
  71.  
  72. VOID blank( VOID )
  73. {
  74.     struct    Screen    *Scr;
  75.         LONG    i;
  76.  
  77.     if( Scr = OpenScreenTags( NULL, SA_Depth, Depth, SA_Overscan, OSCAN_STANDARD, SA_DisplayID, Mode, SA_Quiet,
  78.         TRUE, SA_Behind, TRUE, TAG_DONE )) {
  79.  
  80.         Wid = Scr->Width;
  81.         Hei = Scr->Height;
  82.  
  83.         CycleColors( Scr, Depth );
  84.         BlankMousePointer();
  85.         ScreenToFront( Scr );
  86.  
  87.         if( Cell = AllocVec( Wid * Hei * sizeof( WORD ), MEMF_CLEAR )) {
  88.  
  89.             while(!( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )){
  90.  
  91.                 SetRast(&( Scr->RastPort ), 0 );
  92.                 grow(&( Scr->RastPort ));
  93.  
  94.                 for( i = 0; ( i < 200 )&&(!( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )); i++ ) {
  95.                     WaitTOF();
  96.                     WaitTOF();
  97.                     CycleColors( Scr, Depth );
  98.                 }
  99.             }
  100.             FreeVec( Cell );
  101.          }
  102.         SetSignal( 0L, SIGBREAKF_CTRL_C );
  103.         UnblankMousePointer();
  104.         CloseScreen( Scr );
  105.     }
  106. }
  107.